<?php
	session_start();
	if (empty($_SESSION['usuario'])){
		session_destroy();
		header("Location:principal.php");
	}
	else{
		$tipo=$_GET["id_tipo"];
		$usuario=$_GET["id_usuario"];
	}
?>
<html>
	<head>
		<title>LA CIUDAD DE LOS LIBROS</title>
		<link href="../css/estilo.css" rel="stylesheet" type="text/css" />
	</head>
	<body>
		<div class="titulo">Hist&oacute;rico de ventas</div>
		<div class="menu">
			<?php
				include ("menu.php");
				if (empty($_SESSION['usuario'])){
					nomenu();
				}
				else{
					menu($tipo,$usuario);
				}
			?>
		</div>
		<div class="contenido">
			<div class="cerrarsesion">
				<?php echo $usuario;?> | <a href="principal.php">Cerrar Sesi&oacute;n</a>
			</div>
			<marquee><h1 align=\"center\">LIBRER&Iacute;A VIRTUAL </h1></marquee>
			<?php 
				include ("conexion.php");
				$consulta="SELECT * FROM ventas;";
				$resultado=mysql_query($consulta,$conexion);
				if (mysql_num_rows($resultado)<>0){
					echo "<title>"."Datos completos de las ventas"."</title>";
					echo "<h3 align=center>Datos completos de las ventas</h3>";
					echo "<TABLE align=center BORDER=\"1\" CELLSPACING=\"1\" CELLPADDING=\"1\">";
						echo "<TR>";
							echo "<TD align=center><b>&nbsp;Tipo&nbsp;</b></TD>";
							echo "<TD align=center><b>&nbsp;Autor&nbsp;</b></TD>";
							echo "<TD align=center><b>&nbsp;T&iacute;tulo&nbsp;</b></TD>";
							echo "<TD align=center><b>&nbsp;Editorial&nbsp;</b></TD>";
							echo "<TD align=center><b>&nbsp;A&#241;o&nbsp;</b></TD>";
							echo "<TD align=center><b>&nbsp;G&eacute;nero&nbsp;</b></TD>";
							echo "<TD align=center><b>&nbsp;Precio&nbsp;</b></TD>";
							echo "<TD align=center><b>&nbsp;Fechas&nbsp;</b></TD>";
						echo "</TR>";
						$total_admin=0;
						$num_admin=0;
						$total_vender=0;
						$num_vender=0;
						$total_clien=0;
						$num_clien=0;
						while ($fila=mysql_fetch_array($resultado)){
							echo "<TR>";
								echo "<TD>&nbsp;".$fila["tipo"]."</TD>";
								echo "<TD>&nbsp;".$fila["autor"]."</TD>";
								echo "<TD>&nbsp;".$fila["titulo"]."</TD>";
								echo "<TD>&nbsp;".$fila["editorial"]."</TD>";
								echo "<TD>&nbsp;".$fila["ano"]."</TD>";
								echo "<TD>&nbsp;".$fila["genero"]."</TD>";
								echo "<TD>&nbsp;".$fila["precio"]."</TD>";
								echo "<TD>&nbsp;".$fila["fecha_venta"]."</TD>";
							echo "</TR>";
							if ($fila["tipo"]=="administrador"){
								$total_admin=$total_admin+$fila["precio"];
								$num_admin=$num_admin+1;
							}
							else{
								if ($fila["tipo"]=="vendedor"){
									$total_vender=$total_vender+$fila["precio"];
									$num_vender=$num_vender+1;
								}
								else{
									$total_clien=$total_clien+$fila["precio"];
									$num_clien=$num_clien+1;
								}
							}
						}
					echo "</table>";
					echo "<br>";
					echo "<form action=\"imprimirpdf.php?id_tipo=$tipo&id_usuario=$usuario\" method=\"post\">";
						echo "<div id='boton_buscar'>";
							echo "<input type='submit' value='Imprimir en PDF' name='enviar' class='boton'>";
						echo "</div>";
					echo "</form>";
					echo "</form>";
						echo "<form action=\"grafica.php?id_tipo=$tipo&id_usuario=$usuario\" method=\"post\">";
							echo "<input type=\"hidden\" name=\"total_admin\" value=\"$total_admin\"/>";
							echo "<input type=\"hidden\" name=\"num_admin\" value=\"$num_admin\"/>";
							echo "<input type=\"hidden\" name=\"total_vender\" value=\"$total_vender\"/>";
							echo "<input type=\"hidden\" name=\"num_vender\" value=\"$num_vender\"/>";
							echo "<input type=\"hidden\" name=\"total_clien\" value=\"$total_clien\"/>";
							echo "<input type=\"hidden\" name=\"num_clien\" value=\"$num_clien\"/>";
						echo "<div id='boton_buscar'>";
							echo "<input type='submit' value=' Ver gr&aacute;fico' name='enviar' class='boton'>";
						echo "</div>";
					echo "</form>";
				}
				else{
					echo "<h2 align=\"center\">Ning&uacute;n resultado encontrado. Busque con otro criterio</h2>";
				}
				mysql_close($conexion);
			?>
		</div>
		<div class="pie">Carlos Guerrero Rodr&iacute;guez &#169;</div>
	</body>
</html>